using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Main.controls;

namespace Main
{
    public partial class ShowPolls : System.Web.UI.Page
    {
        protected ShowPoll myShowPoll;
        protected ShowComment myComments;
        protected PollCollection myPolls = new PollCollection();
        protected Poll myPoll = new Poll();
        protected CommentCollection pollComments = new CommentCollection();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (User.Identity.IsAuthenticated)
            {
                if (Request.QueryString["form"] == "MyPolls")
                {
                    header.Text = "My Polls";
                    myPolls.FillAllForUser((Guid)Membership.GetUser().ProviderUserKey);

                    foreach (Poll poll in myPolls)
                    {
                        // The control must be loaded for each poll.
                        myShowPoll = (ShowPoll)LoadControl("controls/ShowPoll.ascx");
                        myShowPoll.PollID = poll.ID;
                        MainPanel.Controls.Add(myShowPoll);
                    }
                }
                else if (Request.QueryString["form"] == "Poll")
                {
                    int pollId = Convert.ToInt32(Request.QueryString["id"]);

                    myShowPoll = (ShowPoll)LoadControl("controls/ShowPoll.ascx");
                    myShowPoll.PollID = pollId;
                    MainPanel.Controls.Add(myShowPoll);

                    MainPanel.Controls.Add((CreateComment)LoadControl("controls/CreateComment.ascx"));

                    pollComments.GetCommentsForPoll(pollId);
                    foreach (Comment comment in pollComments)
                    {
                        myComments = (ShowComment)LoadControl("controls/ShowComment.ascx");
                        myComments.CommentID = comment.ID;
                        MainPanel.Controls.Add(myComments);
                    }
                }
            }
        }
    }
}
